﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AlgorithmResult;
using System.Data;

namespace TripletSegmentationGUI
{
    public class StandartDeviationLength :StandartDeviation
    {
        public StandartDeviationLength(DataTable table, Result result, Dictionary<String, int> CodonMap)
            : base(table, 
                result, 
                CodonMap){        
        }
        public override double CalculateStandardDeviation()
        {
            try
            {

                double sum = 0;
                for (int i = 0; i < result.NumOfBoundaries; ++i)
                {
                    if (i == 0)
                    {
                        sum += Math.Pow(((double)(result.BoundariesSet[i]) - (double)table.Rows[CodonMap[result.ArchreTriplets[i]]][DataTableResult.STR_AverageFragmentLength]), 2);
                    }
                    else
                    {

                        sum += Math.Pow(((double)(result.BoundariesSet[i] - result.BoundariesSet[i - 1]) - (double)table.Rows[CodonMap[result.ArchreTriplets[i]]][DataTableResult.STR_AverageFragmentLength]), 2);
                    }
                }
                sigma = Math.Pow((double)((double)sum / (double)result.NumOfBoundaries), 0.5);

                return sigma;
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
            return 0;
        }
    }
}
